﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class tset2 : System.Web.UI.Page
{
    public static int f;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            binddata();
        }
    }
    protected void binddata()
    {
        string str = "SELECT [id] FROM [applylist];";
        sqldata sd = new sqldata();
        sd.dropdownlistdatabind(str, ddl1);
        ListItem nulllist = new ListItem();
        ddl1.Items.Insert(0, nulllist);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        P2.Visible = true;
        f = 0;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        P2.Visible = true;
        f = 1;
    }
    protected void bton_Click(object sender, EventArgs e)
    {
        if (ddl1.Text == "" && Tdata.Text == "" && Tdata1.Text == "")
        {
            Response.Write("<script>alert('请输入查询条件')</script>");
        }
        else
            if (Tdata.Text != "" && Tdata1.Text == "")
            {
                Response.Write("<script>alert('请输入截止日期')</script>");
            }
            else
                if (Tdata.Text == "" && Tdata1.Text != "")
                {
                    Response.Write("<script>alert('请输入开始日期')</script>");
                }
                else
                {
                    string strid = ddl1.Text;
                    string btime = Tdata.Text.ToString();
                    string ltime = Tdata1.Text.ToString();
                    string str = null;
                    string str1 = "SELECT  id, opeartor_id, appllytime, lend_id, status ,note FROM applylist where id='" + strid + "'";
                    string str2 = "SELECT  id, opeartor_id, appllytime, lend_id, status ,note FROM applylist  WHERE  (appllytime BETWEEN '" + btime + "' AND '" + ltime + "')";
                    string str3 = "SELECT  id, opeartor_id, appllytime, lend_id, status ,note FROM applylist  WHERE  (appllytime BETWEEN '" + btime + "' AND '" + ltime + "') AND (id='" + strid + "')";
                    if ((strid != "") && (btime != "" && ltime != ""))
                    {
                        str = str3;
                    }
                    else
                        if (strid == "")
                        {
                            str = str2;
                        }
                        else
                            if (btime == "" && ltime == "")
                            {
                                str = str1;
                            }
                    sqldata sd = new sqldata();
                    sd.gridviewdatabind(str, GridView1);
                }
    }
    protected void Drop_yuar_SelectedIndexChanged(object sender, EventArgs e)
    {
        Calendar1.VisibleDate = Convert.ToDateTime(this.Drop_yuar.SelectedValue + "-" +
          DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString());
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        if (f == 0)
        {
            this.Tdata.Text = Calendar1.SelectedDate.ToShortDateString();
            P2.Visible = false;
            f = 1;
        }
        else
        {
            this.Tdata1.Text = Calendar1.SelectedDate.ToShortDateString();
            P2.Visible = false;
            f = 0;
        }
    }
    protected void btoff_Click(object sender, EventArgs e)
    {
        ddl1.SelectedIndex = 0;
        Tdata.Text = null;
        Tdata1.Text = null;
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        string cmdtext = "delete from applylist where id='" + id + "'";
        string cmdtext2 = "delete from applylistpack where list_id='" + id + "'";
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["medical"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand(cmdtext, con);
        SqlCommand cmd1 =new SqlCommand(cmdtext2, con);
        cmd.ExecuteNonQuery();
        cmd1.ExecuteNonQuery();
        con.Close();
        Response.Write("<script>alert('删除成功！！')</script>");
        Response.Redirect("deleteappllylist.aspx?");
    }
}
